package com.cljz.makepassenger.ui.activity;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.cljz.makepassenger.R;
import com.cljz.makepassenger.base.BaseActivity;
import com.cljz.makepassenger.present.activity.MineInviteP;
import com.cljz.makepassenger.ui.adapter.InvitePagerAdapter;
import com.cljz.makepassenger.widget.NoScrollViewPager;
import com.jakewharton.rxbinding.view.RxView;
import com.jakewharton.rxbinding.widget.RxRadioGroup;

import butterknife.BindView;
import cn.droidlover.xdroidmvp.router.Router;
import rx.functions.Action1;

/**
 * Created by apple on 2017/4/27.
 */

public class MineInviteActivity extends BaseActivity<MineInviteP> {
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.rb_send_invite)
    RadioButton rbSendInvite;
    @BindView(R.id.rb_receive_invite)
    RadioButton rbReceiveInvite;
    @BindView(R.id.rg_invite_change)
    RadioGroup rgInviteChange;
    @BindView(R.id.nvp_invite)
    NoScrollViewPager nvpInvite;

    @Override
    public void initData(Bundle savedInstanceState) {
        rgInviteChange.check(R.id.rb_send_invite);
        nvpInvite.setCurrentItem(0);
        InvitePagerAdapter invitePagerAdapter = new InvitePagerAdapter(getSupportFragmentManager());
        nvpInvite.setAdapter(invitePagerAdapter);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_mine_invite;
    }

    @Override
    public MineInviteP newP() {
        return new MineInviteP();
    }

    @Override
    protected void initListener() {
        super.initListener();
        RxView.clicks(ivBack)
                .compose(this.<Void>bindToLifecycle())
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        Router.pop(MineInviteActivity.this);
                    }
                });
        RxRadioGroup.checkedChanges(rgInviteChange)
                .compose(this.<Integer>bindToLifecycle())
                .subscribe(new Action1<Integer>() {
                    @Override
                    public void call(Integer integer) {
                        switch (integer) {
                            case R.id.rb_send_invite:
                                nvpInvite.setCurrentItem(0);
                                break;
                            case R.id.rb_receive_invite:
                                nvpInvite.setCurrentItem(1);
                                break;
                        }
                    }
                });
    }
}
